package com.cxria.problem.web.listener

import javax.servlet.ServletContext
import javax.servlet.ServletContextEvent
import javax.servlet.ServletContextListener
import javax.servlet.http.HttpSessionEvent
import javax.servlet.http.HttpSessionListener

class WebAppListener implements ServletContextListener, HttpSessionListener {

	ServletContext application
	
	long userNumber = 0
	
	void contextDestroyed(ServletContextEvent event) {
		
	}

	void contextInitialized(ServletContextEvent event) {
		application = event.getServletContext()
		application.setAttribute('root', application.getContextPath())
	}

	void sessionCreated(HttpSessionEvent event) {
		userNumber++
		application.setAttribute('userNumber', userNumber)
	}

	void sessionDestroyed(HttpSessionEvent event) {
		userNumber--
		application.setAttribute("userNumber", userNumber)
	}

}
